#!/bin/sh
#
# Branch ports from trunk to releng-*.
#
# Run this script each time a port is to be introduced in the FreeBSD Ports
# Tree. Once a port is present in a branch, you shall not use this script with
# it anymore. Rely instead on the MFT and MFC scripts to merge updates from
# trunk. mono-branch should do it's job and maintaining the port after a new
# branch is created should be straightforward.

usage()
{
	echo "usage: $0 -r version port..."
	echo "    version -- Branch to merge to. Should be the \"current\" one. (e.g. 2.4)" >&2
	exit 1
}

r=""

args=`getopt r: $*`
if [ $? -ne 0 ]; then
        usage
fi
set -- $args

for i
do
        case "$i" in
                -r) r="$2"; shift; shift;;
                --) shift; break;;
        esac
done

if [ -z "${r}" ]; then
	usage
fi

branch_name="bsd-sharp-releng-${r}"

svn_root="https://bsd-sharp.googlecode.com/svn"
svn_trunk="${svn_root}/trunk"
svn_branch="${svn_root}/branches/${branch_name}"

for _port; do
	if [ -d "${_port}" ]; then
		svn copy --parents "${svn_trunk}/${_port}" "${svn_branch}/${_port}" -m "(${branch_name}) import ${_port} from trunk." || exit 1
	else
		echo "Directory ${_port} does not exits." >&2
		exit 1
	fi
done

exit 0
